#include "AppDelegate.h"
#include "GameCommon.h"
#include "CreateCharacterFacade.h"
USING_NS_CC;

AppDelegate::AppDelegate() {

}

AppDelegate::~AppDelegate() 
{
}

bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);

    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);
	CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
	CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
	if (screenSize.height != 640)
    {
        float temp = screenSize.width/screenSize.height;
        float temp1 = 960.0/640.0;
        float temp2 = 1136.0/640.0;
        
        int t1 = abs(int((temp - temp1) * 100));
        int t2 = abs(int((temp - temp2) * 100));
        CCLOG("test:%f,%f,%f,%d,%d",temp,temp1,temp2,t1,t2);
        CCSize designSize;
        CCSize resourceSize;
        if(t1 < t2){
            designSize = CCSizeMake(960, 640);
            resourceSize = CCSizeMake(960, 640);
        }else{
            designSize = CCSizeMake(1136, 640);
            resourceSize = CCSizeMake(1136, 640);
        }
        
        pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
        CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionExactFit);
    }
	INSTANCE(CreateCharacterFacade)->openCreateCharacterScene();
    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
    CCDirector::sharedDirector()->stopAnimation();

    // if you use SimpleAudioEngine, it must be pause
    // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
    CCDirector::sharedDirector()->startAnimation();

    // if you use SimpleAudioEngine, it must resume here
    // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}